package com.mdxx.xczd.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.mdxx.xczd.R;
import com.mdxx.xczd.bean.TestBean;
import com.mdxx.xczd.utils.FormatUtil;
import java.util.List;

public class TestAdapter extends BaseAdapter{

    private Context context;
    private List<TestBean> data;

    public TestAdapter(Context context,List<TestBean> data) {
        this.context = context;
        this.data = data;
    }

    public void setData(List<TestBean> data){
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(convertView == null){
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.list_test_item,parent,false);
            viewHolder.text1 = (TextView)convertView.findViewById(R.id.tv_text1);
            viewHolder.text2 = (TextView)convertView.findViewById(R.id.tv_text2);
            viewHolder.text3 = (TextView)convertView.findViewById(R.id.tv_text3);
            convertView.setTag(viewHolder);
        }else{
            viewHolder =  (ViewHolder)convertView.getTag();
        }

        viewHolder.text1.setText("发起时间："+ FormatUtil.getSSSTime(data.get(position).getTime1()));
        viewHolder.text2.setText("已成功发送，接收时间：\n"+ FormatUtil.getSSSTime(data.get(position).getTime2()));
        viewHolder.text3.setText("耗时："+data.get(position).getTime()+"ms");
        return convertView;
    }

    class ViewHolder{
        TextView text1;
        TextView text2;
        TextView text3;
    }
}
